#include "motor.h"
#include "pwm_out.h"
#include <math.h>

#define PWM_CHA 0
#define PWM_CHB 1

void motor_init(void)
{
	close_motor();
	pwm_out_close();
}

void motor_reset(void)
{
	close_motor();
	pwm_out_close();
}

void motor_update(float duty)
{
	uint8_t dir = 0;
	open_motor();
	
	dir = duty>=0.0f?1:0;
	
	if(dir)
	{
		pwm_out(PWM_CHA, fabs(duty));
	}
	else
	{
		pwm_out(PWM_CHB, fabs(duty));
	}
}
